package softtest3;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class bill {
    //输入：开始时间 结束时间
//输出：话费

    public long checkTime(String time1, String time2) throws ParseException {
        long nm = 1000 * 60;
        long minDiff;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date t1 = format.parse(time1);
        Date t2 = format.parse(time2);
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(t1);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(t2);
        long timeDiff = cal2.getTime().getTime() - cal1.getTime().getTime();

        if(timeDiff>=0 && (timeDiff/1000<60 || timeDiff%nm>0))
            minDiff = timeDiff/nm+1;
        else
            minDiff = timeDiff/nm;

        if(cal1.get(Calendar.MONTH) == Calendar.NOVEMBER && (cal1.get(Calendar.DATE) ==2||cal1.get(Calendar.DATE) ==3)
                &&cal2.get(Calendar.MONTH) == Calendar.NOVEMBER && cal2.get(Calendar.DATE)  == 3) {
            if(cal1.get(Calendar.DATE) ==3){
            //如果开始时间为两点及之后，结束时间为两点之后，并且结束时间小于开始时间，代表跨过了秋令时，分钟要加60
            if(cal1.get(Calendar.HOUR_OF_DAY)==2 && cal2.get(Calendar.HOUR_OF_DAY)==2 && cal2.get(Calendar.HOUR_OF_DAY)<3
                    && cal2.get(Calendar.MINUTE)<=cal1.get(Calendar.MINUTE))
                minDiff+=60;
            //如果开始时间为两点及之后，结束时间大于两点，也代表跨过了秋令时，分钟要加60
            else if(cal1.get(Calendar.HOUR_OF_DAY)==2 &&cal2.get(Calendar.HOUR_OF_DAY)>2)
                    minDiff +=60;}
            if(cal1.get(Calendar.DATE) ==2){
            //要考虑前一天并不是冬令时，而是冬令时的前一天，但是结束时间又跨过了冬令时
           if (cal2.get(Calendar.HOUR_OF_DAY)>2&&cal2.get(Calendar.SECOND)>0)
                minDiff +=60;
            }
        }

        if(cal1.get(Calendar.MONTH) == Calendar.MARCH && (cal1.get(Calendar.DATE) == 10||cal1.get(Calendar.DATE) == 9)
                &&cal2.get(Calendar.MONTH) == Calendar.MARCH && cal2.get(Calendar.DATE) == 10) {
            if (cal1.get(Calendar.DATE) == 10){
                //若开始时间小于2点，结束时间大于三点，代表跨过了夏令时，分钟要减60
                if (cal1.get(Calendar.HOUR_OF_DAY) < 2 && cal2.get(Calendar.HOUR_OF_DAY) >= 3)
                    minDiff -= 60;
                //开始时间为2点整，结束时间大于三点，代表跨过了夏令时，分钟要减60
                else if (cal1.get(Calendar.HOUR_OF_DAY) ==2 &&cal1.get(Calendar.MINUTE
                ) ==0&&cal1.get(Calendar.SECOND) ==0&& cal2.get(Calendar.HOUR_OF_DAY) >= 3)
                    minDiff -= 60;

                //若时间在夏令时这天是2点到3点之间，则表示输入错误，因为这天不存在这个时间段
                else if ((cal1.get(Calendar.HOUR_OF_DAY) == 2 && cal1.get(Calendar.SECOND) > 0) ||
                        (cal2.get(Calendar.HOUR_OF_DAY) == 2 && cal2.get(Calendar.SECOND) > 0))
                    minDiff = -1;
        }
            //要考虑前一天并不是夏令时，而是夏令时的前一天，但是结束时间又跨过了夏令时
            if(cal1.get(Calendar.DATE) == 9){
                if (cal2.get(Calendar.HOUR_OF_DAY) >= 3)
                    minDiff -= 60;
            }
        }
        return minDiff;

    }
    public double CountMoney(long time){
        double money = 0;
        if(time <= 0|| time >1800){
            money = -1.0;
        }
        else if(time > 0 && time <=20){
            money = time*0.05;
        }

        else
            money = 1+(time - 20)*0.1;

        return money;
    }



}
